<template>
  <div class="school-permission">
    <div v-for="v in deptData" :key="v.id">
      <h2 v-if="!showCampus">{{ v.name }}</h2>
      <ul v-else>
        <li :class="['sheng', { active: active == '' }]" @click="handleClick(v)"
          ><b>{{ v.name }}</b></li
        >
      </ul>
      <ul v-for="m in v.childList" :key="m.id">
        <li
          v-if="m.type == 1"
          :class="['sheng', { active: m.id == active }]"
          @click="handleClick(m)"
        >
          {{ m.name }}
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
import { openApiSysDeptQuery } from '@/api/openApi'
import { mapGetters } from 'vuex'
export default {
  data() {
    return {
      active: '',
      deptData: [],
    }
  },
  props: ['showCampus'],
  computed: mapGetters(['userId', 'userType', 'deptFullData']),
  mounted() {
    this.getList()
  },
  watch: {
    $route() {
      if (this.$route.name == 'review-list') {
        this.getList()
      }
    },
  },
  methods: {
    getList() {
      openApiSysDeptQuery({ pId: 0 }).then((res) => {
        this.deptData = res.data.data
        if (this.userType == 1) {
          if (this.showCampus) {
            this.handleClick(this.deptData[0])
          } else {
            let d = this.deptData[0].childList.filter((v) => v.type == 1)[0]
            this.handleClick(d)
          }
        } else {
          this.handleClick(this.deptFullData.childList[0])
        }
      })
    },
    handleClick(v) {
      if (v.pid == 0) {
        this.active = ''
      } else {
        this.active = v.id
      }
      this.$emit('e-emit', v)
    },
  },
}
</script>
<style scoped lang="scss">
.school-permission {
  h2 {
    font-size: 16px;
    height: 42px;
    line-height: 42px;
    color: #333;
    border-bottom: 1px solid #ddd;
  }
  ul {
    box-sizing: border-box;
    li {
      font-size: 14px;
      color: #666;
      height: 42px;
      line-height: 42px;
      text-indent: 15px;
      border-bottom: 1px solid #ebeef5;
      border-left: 5px solid transparent;
      cursor: pointer;
      &:hover {
        color: $mainColor;
      }
      &.active {
        background: #f5f7fa;
        border-left-color: $mainColor;
      }
    }
  }
}
</style>